package com.flushbonading.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.flushbonading.mapper.OperatingPostMapper;
import com.flushbonading.mapper.UserMapper;
import com.flushbonading.pojo.Student;
import com.flushbonading.mapper.StudentMapper;
import com.flushbonading.pojo.User;
import com.flushbonading.pojo.dto.ProjectStudentDTO;
import com.flushbonading.pojo.dto.StudentDTO;
import com.flushbonading.pojo.dto.StudentMessageDTO;
import com.flushbonading.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flushbonading.util.GradeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zlx&zyx
 * @since 2021-04-07
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private OperatingPostMapper operatingPostMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 通过学号获得学生信息
     * @param user_id
     * @return
     */
    @Override
    public Student getStudent(String user_id) {
        return studentMapper.getStudent(user_id);
    }

    @Override
    public String getNameByStudnetNum(String student_number) {
        return studentMapper.getNameByStudentNum(student_number);
    }

    @Override
    public StudentDTO selectStudentMessage(String student_number) {
        return studentMapper.selectStudentMessage(student_number);
    }

    @Override
    public int updateStudentMessage(StudentDTO studentDTO, String student_number) {
        return studentMapper.updateStudentMessage(studentDTO,student_number);
    }

    @Override
    public int updateProjectID(int project_id) {
        return studentMapper.updateProjectID(project_id);
    }

    @Override
    public int updateProject(int project_id,ProjectStudentDTO projectStudentDTO) {
        int operatingPostID = operatingPostMapper.getIDByName(projectStudentDTO.getJob_position());
        int j = -1;
        if (operatingPostID>0){
            j = studentMapper.updateProject(projectStudentDTO.getStudent_number(), project_id, operatingPostID, projectStudentDTO.getTechnical_direction());
        }
        return j;
    }

    @Override
    public int atTheProjectCounts(String student_number) {
        return studentMapper.atTheProjectCounts(student_number);
    }

    @Override
    public Integer getProjectIDByStudentNumber(String student_number) {
        return studentMapper.getProjectIDByStudentNumber(student_number);
    }

    @Override
    public String getName(String student_number) {
        return studentMapper.getName(student_number);
    }

    @Override
    public List<StudentMessageDTO> getAllStudent() {
        return studentMapper.getAllStudent();
    }

    @Override
    public int deleteAStudent(String student_number) {
        return studentMapper.deleteAStudent(student_number);
    }

    @Override
    public int updateStudentMessageByStudentNumber(StudentMessageDTO studentMessageDTO) {
        return studentMapper.updateStudentMessageByStudentNumber(studentMessageDTO);
    }

    @Override
    public int insertAStudent(StudentMessageDTO studentMessageDTO) {
        int i = studentMapper.insertAStudent(GradeUtil.getGrade(), studentMessageDTO);
        int j = -1;
        if (i>0){
            j = userMapper.insertAUser(studentMessageDTO.getStudent_number(),studentMessageDTO.getRole_name());
        }
        return j;
    }

    @Override
    public List<StudentMessageDTO> searchByName(String name) {
        return studentMapper.searchByName(name);
    }
}
